WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
track_matrix.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
23
24#include <map>
25#include <vector>
26#include <list>
27#include <utility>
28
29namespace wolf
30{
31using std::list;
32using std::map;
33using std::pair;
34using std::shared_ptr;
35using std::vector;
36
37typedef map<TimeStamp, FeatureBasePtr> Track;
38typedef map<TimeStamp, FeatureBaseConstPtr> TrackConst;
39typedef map<SizeStd, FeatureBasePtr> Snapshot;
40typedef map<SizeStd, FeatureBaseConstPtr> SnapshotConst;
41typedef map<SizeStd, pair<FeatureBasePtr, FeatureBasePtr> > TrackMatches; // matched feature pairs indexed by track_id
42typedef map<SizeStd, pair<FeatureBaseConstPtr, FeatureBaseConstPtr> >
43 TrackMatchesConst; // matched feature pairs indexed by track_id
44
91{
92 public:
96
99 virtual ~TrackMatrix();
100
103 void newTrack(FeatureBasePtr _ftr);
104
107 void add(const SizeStd& _track_id, const FeatureBasePtr& _ftr);
108
111 void add(const FeatureBasePtr& _ftr_existing, const FeatureBasePtr& _ftr_new);
112
115 void remove(FeatureBasePtr _ftr);
116
119 void remove(const SizeStd& _track_id);
120
123 void remove(CaptureBasePtr _cap);
124
127 SizeStd numTracks() const;
128
131 SizeStd trackSize(const SizeStd& _track_id) const;
132
135 TrackConst track(const SizeStd& _track_id) const;
136
139 Track track(const SizeStd& _track_id);
140
143 SnapshotConst snapshot(CaptureBaseConstPtr _capture) const;
144
147 Snapshot snapshot(CaptureBasePtr _capture);
148
151 vector<FeatureBaseConstPtr> trackAsVector(const SizeStd& _track_id) const;
152
155 vector<FeatureBasePtr> trackAsVector(const SizeStd& _track_id);
156
159 FeatureBaseConstPtrList snapshotAsList(CaptureBaseConstPtr _cap) const;
160
163 FeatureBasePtrList snapshotAsList(CaptureBasePtr _cap);
164
167 TrackMatchesConst matches(CaptureBaseConstPtr _cap_1, CaptureBaseConstPtr _cap_2) const;
168
171 TrackMatches matches(CaptureBasePtr _cap_1, CaptureBasePtr _cap_2);
172
175 FeatureBaseConstPtr firstFeature(const SizeStd& _track_id) const;
176
179 FeatureBasePtr firstFeature(const SizeStd& _track_id);
180
183 FeatureBaseConstPtr lastFeature(const SizeStd& _track_id) const;
184
187 FeatureBasePtr lastFeature(const SizeStd& _track_id);
188
191 FeatureBaseConstPtr feature(const SizeStd& _track_id, CaptureBaseConstPtr _cap) const;
192
195 FeatureBasePtr feature(const SizeStd& _track_id, CaptureBasePtr _cap);
196
199 CaptureBaseConstPtr firstCapture(const SizeStd& _track_id) const;
200
203 CaptureBasePtr firstCapture(const SizeStd& _track_id);
204
207 CaptureBaseConstPtr lastCapture(const SizeStd& _track_id) const;
208
211 CaptureBasePtr lastCapture(const SizeStd& _track_id);
212
215 list<SizeStd> trackIds(CaptureBaseConstPtr _capture = nullptr) const;
216
219 CaptureBaseConstPtrList captures() const;
220
223 CaptureBasePtrList captures();
224
231 CaptureBaseConstPtr capture(const TimeStamp& _ts, const double& _time_tolerance) const;
232
239 CaptureBasePtr capture(const TimeStamp& _ts, const double& _time_tolerance);
240
241 // tracks across captures that belong to keyframe
244 TrackConst trackAtKeyframes(const SizeStd& _track_id) const;
245
248 Track trackAtKeyframes(const SizeStd& _track_id);
249
250 // Remove snapshots of captures that are being removed from the problem (e.g. when a keyframe is removed)
253 void cleanSnapshots();
254
255 private:
256 static SizeStd track_id_count_;
257
258 // tracks across all Captures
259 map<SizeStd, Track> tracks_;
260
261 // Across track: maps of Feature pointers indexed by track_Id.
262 map<CaptureBasePtr, Snapshot> snapshots_;
263};
264
265} /* namespace wolf */
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
Matrix of tracked features, by track and by snapshot (Captures or time stamps) This class implements ...
Definition: track_matrix.h:91
CaptureBaseConstPtrList captures() const
Returns the captures of all snapshots, ordered by time stamp.
Definition: track_matrix.cpp:388
TrackConst trackAtKeyframes(const SizeStd &_track_id) const
Returns the features of a track whose captures belong to a keyframe (in the problem)
Definition: track_matrix.cpp:329
SnapshotConst snapshot(CaptureBaseConstPtr _capture) const
Returns the snapshot of a capture: its features indexed by track id.
Definition: track_matrix.cpp:52
list< SizeStd > trackIds(CaptureBaseConstPtr _capture=nullptr) const
Returns the ids of the tracks of a capture snapshot (all tracks if nullptr)
Definition: track_matrix.cpp:369
virtual ~TrackMatrix()
Destructor.
Definition: track_matrix.cpp:30
TrackMatchesConst matches(CaptureBaseConstPtr _cap_1, CaptureBaseConstPtr _cap_2) const
Returns the pairs of features of two captures in the same track, indexed by track id.
Definition: track_matrix.cpp:246
CaptureBaseConstPtr capture(const TimeStamp &_ts, const double &_time_tolerance) const
Returns the capture of the snapshot closest to a time stamp, within a time tolerance.
Definition: track_matrix.cpp:412
CaptureBaseConstPtr firstCapture(const SizeStd &_track_id) const
Returns the capture of the oldest feature of a track.
Definition: track_matrix.cpp:309
FeatureBaseConstPtrList snapshotAsList(CaptureBaseConstPtr _cap) const
Returns the features of the snapshot of a capture as a list.
Definition: track_matrix.cpp:227
void remove(FeatureBasePtr _ftr)
Removes a feature from its track and snapshot.
Definition: track_matrix.cpp:132
void add(const SizeStd &_track_id, const FeatureBasePtr &_ftr)
Adds a feature (linked to a capture) to an existing track, setting its track id.
Definition: track_matrix.cpp:81
CaptureBaseConstPtr lastCapture(const SizeStd &_track_id) const
Returns the capture of the newest feature of a track.
Definition: track_matrix.cpp:319
FeatureBaseConstPtr lastFeature(const SizeStd &_track_id) const
Returns the newest feature of a track.
Definition: track_matrix.cpp:189
vector< FeatureBaseConstPtr > trackAsVector(const SizeStd &_track_id) const
Returns the features of a track as a vector, ordered by time stamp.
Definition: track_matrix.cpp:205
TrackConst track(const SizeStd &_track_id) const
Returns a track: its features indexed by time stamp.
Definition: track_matrix.cpp:35
SizeStd numTracks() const
Returns the number of tracks.
Definition: track_matrix.cpp:163
FeatureBaseConstPtr feature(const SizeStd &_track_id, CaptureBaseConstPtr _cap) const
Returns the feature of a track in a capture.
Definition: track_matrix.cpp:293
void cleanSnapshots()
Removes the snapshots of the captures being removed (e.g. when a keyframe is removed)
Definition: track_matrix.cpp:153
void newTrack(FeatureBasePtr _ftr)
Creates a new track with a feature.
Definition: track_matrix.cpp:75
TrackMatrix()
Default constructor.
Definition: track_matrix.cpp:25
FeatureBaseConstPtr firstFeature(const SizeStd &_track_id) const
Returns the oldest feature of a track.
Definition: track_matrix.cpp:173
SizeStd trackSize(const SizeStd &_track_id) const
Returns the number of features of a track.
Definition: track_matrix.cpp:168
Definition: capture_base.h:23
map< SizeStd, FeatureBasePtr > Snapshot
Definition: track_matrix.h:39
map< SizeStd, FeatureBaseConstPtr > SnapshotConst
Definition: track_matrix.h:40
std::size_t SizeStd
Other containers size type for the Wolf project.
Definition: wolf.h:66
map< SizeStd, pair< FeatureBaseConstPtr, FeatureBaseConstPtr > > TrackMatchesConst
Definition: track_matrix.h:43
map< SizeStd, pair< FeatureBasePtr, FeatureBasePtr > > TrackMatches
Definition: track_matrix.h:41
map< TimeStamp, FeatureBaseConstPtr > TrackConst
Definition: track_matrix.h:38
map< TimeStamp, FeatureBasePtr > Track
Definition: track_matrix.h:37